package uit.jee.lib.bo;

import java.util.ArrayList;
import uit.jee.lib.access.mapper.WriterMapper;
import uit.jee.lib.dto.WriterDTO;

/**
 *
 * @author ngloc_it
 */
public class WriterBO {
    private WriterMapper mapper;

    public WriterBO() throws Exception {
        mapper = new WriterMapper();
    }

    public boolean CheckWriterExited(String writerId) throws Exception{
        return mapper.CheckWriterExited(writerId);
    }

    public ArrayList<WriterDTO> GetAllWriter() throws Exception{
        return mapper.GetAllWriter();
    }

    public ArrayList<WriterDTO> GetAllWriterByAuthorId(String authorId) throws Exception{
        if(authorId == null){
            throw new Exception("Author's Id is null");
        }

        return mapper.GetAllWriterByAuthorId(authorId);
    }

    public ArrayList<WriterDTO> GetAllWriterByAuthorName(String authorName) throws Exception{
        if(authorName == null){
            throw new Exception("Author's name is null");
        }

        return mapper.GetAllWriterByAuthorName(authorName);
    }

    public ArrayList<WriterDTO> GetAllWriterOnBook(String bookId) throws Exception{
        if (bookId == null) {
            throw new Exception("Book's id is null");
        }
        return mapper.GetAllWriterOnBook(bookId);
    }

    public void Insert(WriterDTO wr) throws Exception{
        if (wr == null){
            throw new Exception("Wr is null");
        }

        if (wr.isValidate()){
            throw new Exception("Wr is not validated");
        }
        mapper.Insert(wr);
    }

    public void Insert(WriterDTO[] wrs) throws Exception{
        if (wrs == null){
            throw new Exception("wrs is null");
        }
        mapper.Insert(wrs);;
    }

    public void Update(WriterDTO wr) throws Exception{
        mapper.Update(wr);
    }

    public void Update(WriterDTO[] wr) throws Exception{
        mapper.Update(wr);
    }

    public void Delete(WriterDTO wr) throws Exception{
        mapper.Delete(wr);
    }

    public void Delete(WriterDTO[] wr) throws Exception{
        mapper.Delete(wr);
    }

    public void Delete(String writerId) throws Exception{
        mapper.Delete(writerId);
    }

    public void Delete(String[] writerIds) throws Exception{
        mapper.Delete(writerIds);
    }
}
